#[cfg(test)]
pub mod format_json {
    use std::{env, fs};
    use std::path::Path;
    use crate::json::parser;

    #[test]
    pub fn pretty() {
        format_json(parser::JSON::pretty)
    }

    #[test]
    pub fn compress() {
        format_json(parser::JSON::compress)
    }

    pub fn format_json(handler: fn(&String) -> String) {
        let root_dir = env::current_dir().unwrap();
        let test_dir_path = root_dir.as_path().to_str().unwrap().to_owned() + "\\test_data";
        println!("根目录：{}", test_dir_path);

        let test_dir = fs::read_dir(Path::new(&test_dir_path)).unwrap();
        for entry in test_dir {
            if let Err(err) = entry {
                println!("遍历文件出错：{}", err.to_string());
                continue;
            }
            let file = entry.unwrap();

            let metadata = file.metadata().unwrap();
            if metadata.is_dir() {
                continue;
            }

            println!("格式化输入文件：{}", file.path().to_str().unwrap());
            let str = fs::read_to_string(file.path()).unwrap();

            //执行处理
            let json_str = handler(&str);

            let mut out_file = String::new();
            out_file.push_str(&test_dir_path);
            out_file.push_str("/out_json/");
            out_file.push_str(file.file_name().to_str().unwrap());

            println!("格式化输出文件：{}", out_file);

            fs::write(Path::new(&out_file), json_str).unwrap();
        }
    }
}